package ad
{
	import UIFree.controls.uif_close;
	import UIFree.uif_Timer;
	import UIFree.uif_ecomponent;
	import UIFree.uif_loader;
	
	import components.resultLayer.clt_resultLayer;
	
	import flash.events.Event;
	import flash.geom.Rectangle;

	public class clt_ad extends uif_ecomponent {
		private const genders: Object = ['f', 'm'];

		private const banners: Array = [
			[
				'http://start.fotostrana.ru/promo/fotostrana/240x400/240x400_9.swf',
				'http://start.fotostrana.ru/promo/fotostrana/240x400/240x400_choose.swf'
			],[
				'http://start.fotostrana.ru/promo/fotostrana/240x400/240x400_13.swf',
				'http://start.fotostrana.ru/promo/fotostrana/240x400/240x400_14.swf'
			]
		];
		private const ref_id: String = '468282879';
		private var _block: uif_ecomponent;


		
		private function URLBanner(sex: int): String {
			if (banners[sex] is Array) return banners[sex][Math.floor(Math.random() * (banners[sex] as Array).length)];
			else return banners[sex];
		}
		
		public function clt_ad(parent: clt_resultLayer) {
			var inner: Rectangle = parent.getInner();
			super(parent);
			
			
			var user: Object = (app as clt_clothingBase).user;
			var params: String = '?link1=http%3A%2F%2Ffotostrana.ru%2Fguessnew%2Flanding%2F%3Fltype%3D1%26ref_id=' + ref_id + '&gender=' + genders[user.sex];
			var loader: uif_loader = new uif_loader(null, URLBanner(user.sex) + params, function(e: Event): void {
				_block = new uif_ecomponent(This, -e.target.width - 5, (inner.height - e.target.height) / 2,
											e.target.width, e.target.height, 'modalGurtain');
				_block.addChild(loader);
				_block.addEvent(Event.CLOSE, function(e: Event): void {
					_block.fx('x', _block.x, -_block.width).start(function(e: Event): void {
						dispose();
					});
				});
				
				new uif_Timer(10000, null, function(e: Event): void {
					_block.fx('x', _block.x, 0).start();
					var close: uif_close = new uif_close(_block);
					close.x 	= _block.width - close.width / 2;
					close.y 	= - close.height / 2;
				}, 1);
			});
		}
	}
}